<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <input type="text" name="" id="pwd">
  <input type="button" value="验证密码" id="valid">
  <script>
    // passwordValid("aA.-@)(*12345"); 
    document.getElementById("valid").onclick = function(){
      let str = document.getElementById("pwd").value;
      if(passwordValid(str)){
        alert("密码符合要求")
      }else{
        alert("密码不符合要求")
      }
    }  
    //封装一个函数，密码验证
    function passwordValid(password){
      let count = 0;//计数器
      if(password.length < 6){
        alert("密码长度不能小于6");
      }else if(password.search(/[^A-Za-z0-9\.\-@]/g) == -1){
        if(/[A-Z]/.test(password)){
          count++;
        }
        if(/[a-z]/.test(password)){
          count++;
        }
        if(/[0-9]/.test(password)){
          count++;
        }
        if(/[\.\-@]/.test(password)){
          count++;
        }
      }else{
        alert("密码有非法字符");
      }
      if(count >=3 ){
        return true;
      }
      return false;
    }    
  </script>
</body>
</html>